<?php
require_once('functions.php');
class Form {
	public static function openForm($action='',$method='post',$name='',$id='',$attr=''){
		echo '<form id="'.$id.'" name="'.$name.'" action="'.$action.'" method="'.$method.'" '.$attr.'>';
	}
	
	public static function closeForm(){
		echo '</form>';
	}
	
	
	public static function createInputField($type,$label,$name,$value='',$required=false, $attr=''){
		$req_section = ($required) ? 'required="required"':'';
		echo '<label for="'.$name.'">'.$label.'</label>';
		echo '<input type="'.$type.'" id="'.$name.'" name="'.$name.'" value="'.$value.'" '.$req_section.' '.$attr.' />';
	}
	
	public static function createTextArea($label,$name, $value='', $required=false, $rows='',$cols='', $attr=''){
		$req_section = ($required) ? 'required="required"':'';
		$_attr='';
		if($rows != '' || $cols!=''){
			$_attr = 'rows="'.$rows.'" cols="'.$cols.'" '.$attr;
		}else{
			$_attr = $attr;
		}
		echo '<label for="'.$name.'">'.$label.'</label>';
		echo '<textarea id="'.$name.'" name="'.$name.'" '.$req_section.' '.$_attr.'>'.$value.'</textarea>';
	}
	
	public static function createJSButton($text='', $onclick='', $id='',$attr=''){
		echo '<input type="button" id="'.$id.'" value="'.$text.'" onclick="'.$onclick.'" '.$attr.' />';
	}
	
	public static function createDropDownBox($label, $name, $placeholder, $options=array('0'=>'No option available'), $attr='', $required = false, $default_value=''){
		$req_section = ($required) ? 'required="required"':'';
		
		echo '<label for="'.$name.'">'.$label.'</label>';
		echo '<select id="'.$name.'" name="'.$name.'" '.$req_section.' '.$attr.'>';
		echo '<option value="" disabled="disabled">'.$placeholder.'</option>';
		foreach($options as $value => $text){
			if($default_value == $value){
				echo '<option value="'.$value.'" selected="selected">'.$text.'</option>';
			}else{
				echo '<option value="'.$value.'">'.$text.'</option>';
			}
		}
		echo '</select>';
	}
	
	public static function submitButton($name='',$value='Submit', $attr=''){
		echo '<input type="submit" name="'.$name.'" value="'.$value.'" '.$attr.' />';
	}
	
	public static function createCheckbox($name,$label,$attr=''){
		echo '<label class="checkbox">';
		echo '<input type="checkbox" name="'.$name.'" '.$attr.' />'.$label;
		echo '</label>';
	}
	
	public static function clearFix(){
		echo '<div class="clearfix"></div>';
	}
	
}
?>